package com.liufei1988.java8.collection;

import java.util.*;

public class MapDemo {

    static class Node<K,V>{

        final int hash;
        final K key;
        V value;
        Node<K,V> next;

        public final K getKey() {
            return key;
        }

        public final V getValue() {
            return value;
        }

        @Override
        public final String toString(){
            return key+"="+value;
        }

        @Override
        public final int hashCode(){
            return Objects.hashCode(key)^Objects.hashCode(value);
        }

        public final V setValue(V newValue){
            V oldValue=value;
            value=newValue;
            return oldValue;
        }

        @Override
        public final boolean equals(Object o){
            if (o==this)
                return true;
            if (o instanceof Map.Entry<?,?>){
                Map.Entry<?,?> e= (Map.Entry<?, ?>) o;
                if (Objects.equals(key,e.getKey())&& Objects.equals(value,e.getValue()))
                    return true;
            }
            return false;
        }

        Node(int hash, K k, V value, Node<K,V> next) {
            this.hash = hash;
            this.key=k;
            this.value=value;
            this.next=next;
        }
    }

    public static void main(String[] args) {

        Map<String,String> map=new HashMap<>();
        map.put("aa","aabb");
        map.put("bb","bbcc");
        map.put("cc","ccdd");
        System.out.println(map);
        Node<String,String> n=new Node<String,String>("aa".hashCode(),"aa","bb",null);

        Node<String,String> n1=new Node<String,String>("aa1".hashCode(),"aa1","bb",n);
        Node<String,String> n2=new Node<String,String>("aa2".hashCode(),"aa2","bb",n1);
        Node<String,String> n3=new Node<String,String>("aa3".hashCode(),"aa3","bb",n2);
        System.out.println(n1);

        String a="111";
        String b="222";
        a.compareTo(b);

        Integer aa=1;
        Integer bb=2;
        aa.compareTo(bb);

    }
}
